<?php

/**
 * @author Martin Pernica
 * @copyright 2008
 */

class DB_MySQL {

	public $conn;
	public $query_count;

	function __construct($host, $user, $pass, $db){
		if( !( $this->conn = mysql_connect( $host, $user, $pass ) ) ) {
            die( "<h1>Cannot establish connection to DB through <strong>mysql</strong> driver!</h1>" );
		}
		mysql_select_db( $db, $conn );
		mysql_query("SET NAMES utf8");
		return $this->conn;
	}

	function query( $query ) {
		$this->query_count++;
		$query = str_replace('{prefix}', $GLOBALS['db_prefix'], $query);
		return mysql_query( $query , $this->conn);
	}

	function fetch_array( $result ) {
		return mysql_fetch_array( $result );
	}
	
	function fetch_object( $result ) {
		return mysql_fetch_object( $result );
	}
	
    function real_escape_string( $escapestr ) {
		return mysql_real_escape_string( $escapestr, $this->conn );
	}
	
	function error(){
		return mysql_error();
	}
}

?>